<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function filterRange(a = [], start, end) {
        for (let i = 0; i < a.length; i++) {
          if (a[i] < start || a[i] > end) {
            a.splice(i, 1);
            i--;
          }
        }
      }
      let arr = [5, 10, 3, 3, 3, 8, 1];
      console.log(arr);

      let filtered = filterRange(arr, 1, 4);
      // console.log(filtered); // 3,1（匹配值）
      console.log(arr); // 5,3,8,1（未修改）
    </script>
  </body>
</html>
